import type { RemoveMethods } from "@/types/remove-methods";
import {beforeDDL} from "@/utils";
import title from "@/router/guard/title";

export class TimeMentionModal {
    constructor(deadLine: number, beforeDDL2Mention: number, beforeDDL2MentionUnit: number, beginMentionTime: number, mentionPeriod: number, mentionUnit: number) {
        this.deadLine = deadLine;
        this.beforeDDL2Mention = beforeDDL2Mention;
        this.beforeDDL2MentionUnit = beforeDDL2MentionUnit;
        this.beginMentionTime = beginMentionTime;
        this.mentionPeriod = mentionPeriod;
        this.mentionUnit = mentionUnit;
    }

    deadLine:number
    beforeDDL2Mention:number
    beforeDDL2MentionUnit:number
    beginMentionTime:number
    mentionPeriod:number
    mentionUnit:number

    static getNewTimeMentionModal(){
        return new TimeMentionModal(Date.now(),0,1,Date.now(),0,1);
    }

    static copyTimeMentionModal(data: RemoveMethods<TimeMentionModal>) {
        const timeModel = new TimeMentionModal(0,0,0,0,0,0);
        Object.assign(timeModel, data);
        return timeModel;
    }
    static change2NextClockTime(time: TimeMentionModal, type:number) {
        const newTime = TimeMentionModal.copyTimeMentionModal(time);
        if (type === 2) {
            const ddl = beforeDDL(newTime.beginMentionTime, newTime.mentionPeriod, newTime.mentionUnit);
            newTime.beginMentionTime = ddl;
        }
        return newTime;
    }
    static computeNextClockTime(time: TimeMentionModal, type:number): number {
        try {
            if (type === 2) {
                const ddl = beforeDDL(time.beginMentionTime, time.mentionPeriod, time.mentionUnit);
                return ddl;
            }
        } catch (e) {
            return 0;
        }
        return 0;
    }
    static computeMentionTime(time: TimeMentionModal, type:number|undefined) {
        try {
            if (time !== undefined) {
                if (type === 1) {
                    return beforeDDL(time.deadLine, time.beforeDDL2Mention, time.beforeDDL2MentionUnit);
                }
                if (type === 2) {
                    const ddl = TimeMentionModal.computeNextClockTime(time,type);
                    time.deadLine = ddl;
                    // console.log(new Date(ddl))
                    // const ddl =  time.deadLine;
                    return beforeDDL(ddl, time.beforeDDL2Mention, time.beforeDDL2MentionUnit);
                }
            }
        } catch (e) {
            return 0;
        }
        return 0;
    }

}

export class UserInfo{
    name:string;
    password:string;
    invitation:string;
    picList:Array<string>;
    invitationList:Array<string>;
    avatar:string;
    timezone:string;

    static getNewUserInfo(){
        return new UserInfo("",'','',[],[],'','')
    }


    constructor(name: string, password: string, invitation: string, picList: Array<string>, invitationList: Array<string>, avatar: string, timezone: string) {
        this.name = name;
        this.password = password;
        this.invitation = invitation;
        this.picList = picList;
        this.invitationList = invitationList;
        this.avatar = avatar;
        this.timezone = timezone;
    }
}

export class MyLocation{
    name:string;
    static getLocation(){
        return new MyLocation('');
    }


    constructor(name: string) {
        this.name = name;
    }
}

export class TaskLogData{
    id:number;
    taskId:number|null;
    taskLogType:number;
    startTime:number;
    endTime:number;
    memory:boolean;
    markDownFile:string;
    picList:Array<string>;
    mediaList:Array<string>;
    location:MyLocation;

    title:string;
    jsonContent:string;
    htmlContent:string;

    taskType:number;
    taskName:string;
    stageName:string;
    stageId:number|null;
    goalId:number|null;
    goalName:string;
    fieldId:number|null;
    fieldName:string;
    lifeModeId:number;
    lifeModeName:string;

    static getNewTaskLogData(){
        return new TaskLogData(0,null,1,Date.now(),Date.now()+1000*60*60*2,false,
            '',[],[],MyLocation.getLocation(),'','','',1,'','',
            null,0,'',null,'',0,'')
    }


    constructor(id: number, taskId: number | null, taskLogType: number, startTime: number, endTime: number,
                memory: boolean, markDownFile: string, picList: Array<string>, mediaList: Array<string>,
                location: MyLocation, title: string, jsonContent: string, htmlContent: string, taskType: number,
                taskName: string, stageName: string, stageId: number | null, goalId: number | null, goalName: string,
                fieldId: number|null, fieldName: string, lifeModeId: number, lifeModeName: string) {
        this.id = id;
        this.taskId = taskId;
        this.taskLogType = taskLogType;
        this.startTime = startTime;
        this.endTime = endTime;
        this.memory = memory;
        this.markDownFile = markDownFile;
        this.picList = picList;
        this.mediaList = mediaList;
        this.location = location;
        this.title = title;
        this.jsonContent = jsonContent;
        this.htmlContent = htmlContent;
        this.taskType = taskType;
        this.taskName = taskName;
        this.stageName = stageName;
        this.stageId = stageId;
        this.goalId = goalId;
        this.goalName = goalName;
        this.fieldId = fieldId;
        this.fieldName = fieldName;
        this.lifeModeId = lifeModeId;
        this.lifeModeName = lifeModeName;
    }
}

export interface TaskPanel{
    name:string
    goalIds:Array<number>
}
export interface TaskMoreData extends TaskData{
    stageName:string;
    goalId:number;
    goalName:string;
    fieldId:number;
    fieldName:string;
    takeTime:number;
    finishRatio:string;
}
export class TaskData{
    id:number|null
    name:string
    state:number
    type:number|undefined
    stageId:number|null
    mentionTime:number|null
    timeMentionModal:TimeMentionModal
    desc:string

    static getNewTaskData(showState:number,type:number|undefined,stageId:number|null){
        return new TaskData(null,"",showState,type,stageId,null,TimeMentionModal.getNewTimeMentionModal(),"");
    }

    constructor(id: number|null, name: string, state: number, type: number|undefined, stageId: number|null, mentionTime: number|null, timeMentionModal: TimeMentionModal, desc: string) {
        this.id = id;
        this.name = name;
        this.state = state;
        this.type = type;
        this.stageId = stageId;
        this.mentionTime = mentionTime;
        this.timeMentionModal = timeMentionModal;
        this.desc = desc;
    }
    // finishTasks
}

export class StageData{
    id:number|null
    name:string
    state:number
    lastStartTime:number
    timePeriods:Array<number>
    fieldId:number
    goalId:number
    finished:boolean
    tasks:Map<number,Map<number,Array<number>>>
    // finishTasks
    constructor(id: number|null, name: string, state: number, lastStartTime: number, timePeriods: Array<number>, fieldId: number, goalId: number, finished: boolean, tasks: Map<number, Map<number, Array<number>>>) {
        this.id = id;
        this.name = name;
        this.state = state;
        this.lastStartTime = lastStartTime;
        this.timePeriods = timePeriods;
        this.fieldId = fieldId;
        this.goalId = goalId;
        this.finished = finished;
        this.tasks = tasks;
    }
    static getNewStageData(){
        return new StageData(null,"",0,0,[],0,0,false,new Map())
    }

}